package kr.hkit.powerjava.chapter10;

import java.util.Scanner;

class StudentTest {
	Scanner input;
	int std;
	int[] sCount;
	
	public StudentTest(){
		input = new Scanner(System.in);
		System.out.print("학생 수를 입력하세요: ");
		std = input.nextInt();
		sCount = new int[std];
	}
	
	public void setSCount() {
		for (int i = 0; i < std; i++) {
			System.out.println("학생 " + (i + 1) + "의 성적을 입력하시오:");
			sCount[i] = input.nextInt();

			if (sCount[i] > 30 || sCount[i] < 0) {
				System.out.println("잘못된 성적입니다. 다시 입력하시오.");
				i--;
				continue;
			}
		}
	}
	
	public void setTotal(){
		double total = 0;
		for (int i = 0; i < sCount.length; i++) {
			total += sCount[i];
		}
		System.out.println("학생들의 평균 성적은 " + (double)(total / std) + "입니다.");
	}
}

public class Student{
	public static void main(String[] args) {	
		StudentTest st = new StudentTest();
		st.setSCount();
		st.setTotal();
	}
}